/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package gameheart.transport;

import java.util.concurrent.ArrayBlockingQueue;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
 *
 * @author win7
 */
public class LocalTransporter implements Transporter{
    private ArrayBlockingQueue<Command> _outCommands = null;
    private ArrayBlockingQueue<Command>_inCommands = null;

    public LocalTransporter(ArrayBlockingQueue<Command> inCommands, ArrayBlockingQueue<Command> outCommands) {
        _inCommands = inCommands;
        _outCommands = outCommands;
    }

    public void SendCommand(Command command) throws MyException {
        _outCommands.add(command);
    }

    public Command GetCommand(boolean waiting) throws MyException {
        Command command = null;
        try {
            if(waiting)
            {
                command =  _inCommands.take();
            }
            else
            {
                command =  _inCommands.poll();
            }
        } catch (InterruptedException ex) {
            Logger.getLogger(LocalTransporter.class.getName()).log(Level.SEVERE, null, ex);
            MyException myEx = new MyException();
            throw myEx;
        }
        return command;
    }

}
